package creature;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Creature
{
	//Data Members//
	private String name = "Name";
	protected int HP = 0;		//it points of creature
	protected int def = 0;	//physical defense of creature
	protected int str = 0;	//attack strength of creature
	protected Attack a1;
	protected Attack a2;
	protected Attack a3;
	protected Attack a4;

	public Creature(String name) throws FileNotFoundException
	{
		//initialize statistics
		FileReader fileIn = new FileReader("Creatures.txt");
		Scanner scanner = new Scanner(fileIn);

		boolean isFound = false;
		while(scanner.hasNext() && !isFound)
		{
			String nameInFile = scanner.next();
			if(nameInFile.equals(name))
			{
				this.name = name;
				this.HP = scanner.nextInt();
				this.def = scanner.nextInt();
				this.str = scanner.nextInt();
				isFound = true;
			}//end if
			else
			{
				String temp = scanner.nextLine();	//skips to next line
			}//end else
		}//end while
		//Build Attacks//
		fileIn = new FileReader("Abilities.txt");
		scanner = new Scanner(fileIn);

		a1 = new Attack(scanner.next(), scanner.nextInt(), scanner.nextInt());
		a2 = new Attack(scanner.next(), scanner.nextInt(), scanner.nextInt());
		a3 = new Attack(scanner.next(), scanner.nextInt(), scanner.nextInt());
		a4 = new Attack(scanner.next(), scanner.nextInt(), scanner.nextInt());

		//TODO the above will happen from database (probably, and eventually).
	}

	public int getHP()
	{
		return this.HP;
	}

	public String getName()
	{
		return this.name;
	}

	public void receiveAttack(Attack a)
	{
		this.HP -= a.damage;
	}

	public Attack getAttack(int attackNo)
	{
		if(attackNo == 1)
			return a1;
		else if (attackNo == 2)
			return a2;
		else if (attackNo == 3)
			return a3;
		else
			return a4;
	}

	public Attack getAttack(String name)
	{
		if(name.equals( a1.getName() ))
			return a1;
		else if(name.equals( a2.getName() ))
			return a2;
		else if(name.equals( a3.getName() ))
			return a3;
		else
			return a4;
	}

	public void printAttacks()
	{
		System.out.println(a1);
		System.out.println(a2);
		System.out.println(a3);
		System.out.println(a4);
	}
}
